﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SpringWaterDataAccess;

namespace test
{
	/// <summary>
	/// Summary description for forumPostReply.
	/// </summary>
	public partial class forumPostReply : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			string postID = Request.QueryString["PostID"];
			string categoryID = Request.QueryString["CategoryID"];

			string categoryName = Request.QueryString["CategoryName"];
			string forumName = Request.QueryString["ForumName"];

			HttpCookie emailCookie = Request.Cookies["Email"];
			if (emailCookie == null) 
			{
				Response.Redirect("index.aspx?message=请你先注册或登录，再回复讨论区文章");
			}
				 
			if (!Page.IsPostBack)
			{

				string subject;
				string body;
				string user;
				string date;
				string topicID;

                if (postID == null)
                {
                    
                }

                //if (postID != null ) 
                //{
                //    ForumDataAccess da = new ForumDataAccess();
                //    da.GetPostDetail(postID, out subject, out body, out user, out date, out topicID);
                //    lblSubject.Text = subject;
				
                //    PostID.Value = postID.ToString();
                //}
                //CategoryID.Value = categoryID.ToString();
               
			}
			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void txtSubject_ServerChange(object sender, System.EventArgs e)
		{
		
		}

		protected void Submit1_ServerClick(object sender, System.EventArgs e)
		{
		
		}

		protected void Submit2_ServerClick(object sender, System.EventArgs e)
		{
		
		}

        protected void Submit2_ServerClick1(object sender, EventArgs e)
        {
            // Put user code to initialize the page here
            string postID = Request.QueryString["PostID"];
            string categoryID = Request.QueryString["CategoryID"];

            string categoryName = Request.QueryString["CategoryName"];
            string forumName = Request.QueryString["ForumName"];

            //save to the database
            string subject = Request.Form["txtSubject"];
            string body = Request.Form["txtBody"];

            HttpCookie nameCookie = Request.Cookies["NickName"];
            HttpCookie mailCookie = Request.Cookies["Email"];

            ForumDataAccess da = new ForumDataAccess();

            DataSet userDS = da.GetUser(mailCookie.Value);
            int userID = Convert.ToUInt16(userDS.Tables[0].Rows[0]["UserID"]);

            string forumID;
            //da.InsertPostReply(postID,categoryID,subject,body,nameCookie.Value, out forumID);

            da.InsertPost(Convert.ToUInt16(postID), Convert.ToUInt16(categoryID), subject, body, userID, "", "bbs", out forumID);


            if (postID == null)
            {
                Response.Redirect(string.Format("forumsStart.aspx?ForumID={0}&CategoryID={1}&ForumName={2}&CategoryName={3}",
                    forumID, categoryID, forumName, categoryName));
            }
            else
            {
                Response.Redirect(string.Format("forumsContent.aspx?PostID={0}",postID));
            }

        }

        protected void Submit1_ServerClick1(object sender, EventArgs e)
        {
            Submit2_ServerClick1(sender, e);
        }

				
	}
}
